package top.wshape1.shiziapi.mock.service.impl;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import top.wshape1.shiziapi.mock.service.JsEngineService;

import javax.script.ScriptEngine;
import javax.script.ScriptException;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2023-10-14
 */

@Service
public class JsEngineServiceImpl implements JsEngineService {

    @Resource
    private ScriptEngine scriptEngine;

    @Override
    public Object mock(String template) throws ScriptException {
        return scriptEngine.eval("Mock.mock(" + template + ")");
    }
}
